<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增分类属性值')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-val-add">
            <input name="quotationClassId" type="hidden" id="treeId"/>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">分类ID：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="quotationClassName" onclick="selectQClassTree()" id="treeName" placeholder="请选择所属分类" class="form-control" type="text"  readonly="true" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">属性名ID：</label>
                <div class="col-sm-8" >
<!--                    <input name="attrKeyId" class="form-control" type="text" required>-->
                    <select name="attrKeyId" id="attrKeyId" class="form-control m-b valid" aria-invalid="false">
<!--                        <option value="572b5bd495ae47d7964dff1dc8d6ee4c">养殖</option>-->
<!--                        <option value="95e0dd521510454995ca00414ee51480">羽绒</option>-->
<!--                        <option value="cb1f441eab9d478d85b7c55909c0791f">水产</option>-->
<!--                        <option value="f4819b66822e4d77b4eb4518cb006825">国家政策</option>-->
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">属性编码：</label>
                <div class="col-sm-8">
                    <input name="attrCode" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">属性值：</label>
                <div class="col-sm-8">
                    <input name="attrVal" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "jiaqin/val"
        $("#form-val-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-val-add').serialize());
            }
        }
        /*属性值管理-新增-选择分类树*/
        function selectQClassTree() {
            var treeId = $("#treeId").val();
            var quotationClassId = $.common.isEmpty(treeId) ? "0" : $("#treeId").val();
            var url = ctx + "jiaqin/quotationclass/selectQuotationClassTree/"+quotationClassId;
            var options = {
                title: '选择分类',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                //根据分类ID获取属性名列表
                $.post("/jiaqin/key/listA",{quotationClassId:body.find('#treeId').val()},function(result){
                   console.log(result);
                   $("#attrKeyId").html('');
                   if(result.data.length!=0){
                       for (i = 0 ;i<result.data.length ;i++){
                           $("#attrKeyId").append("<option value='"+result.data[i].id+"'>"+result.data[i].attrName+"</option>");
                       }
                   }else{
                       $("#attrKeyId").append("<option>此分类下无属性</option>");
                   }
                });
                layer.close(index);
            }
        }
    </script>
</body>
</html>
